package com.anpy.anlibrary.net.interceptor

import android.text.TextUtils
import com.anpy.anlibrary.contants.LibConstants
import com.anpy.anlibrary.utils.MMKVUtils
import okhttp3.Interceptor
import kotlin.Throws
import okhttp3.Request
import okhttp3.Response
import java.io.IOException

/**
 * JohnRambo on 2017/4/11 17:43
 */
class HttpHeadInterceptor : Interceptor {
    @Throws(IOException::class)
    override fun intercept(chain: Interceptor.Chain): Response {
        var accessToken = LibConstants.accessToken
        if (TextUtils.isEmpty(accessToken)) {
            accessToken = MMKVUtils.getString(LibConstants.ACCESS_TOKEN).toString()
        }
        val build: Request = chain.request().newBuilder()
            .addHeader("accessToken", accessToken)
            .addHeader("clientType","APP")
            .build()
        return chain.proceed(build)
    }
}